package com.lagou.client;

import com.lagou.service.UserService;
import org.I0Itec.zkclient.ZkClient;

public class ClientBootStrap {

    public static ZkClient zkClient = new ZkClient("127.0.0.1:2181");

    private static RpcConsumer rpcConsumer = new RpcConsumer();

    public static void main(String[] args) throws InterruptedException {
        //注册监听事件
        zkClient.subscribeChildChanges("/provider", (parentPath, currentChildList) -> {
            System.out.println(parentPath + " 's child changed,currentChildList:" + currentChildList);
            rpcConsumer.connectList(currentChildList);
        });

        RpcConsumer rpcConsumer = new RpcConsumer();
        rpcConsumer.init();
        UserService proxy = (UserService) rpcConsumer.createProxy(UserService.class,"UserService","sayHello");

        while (true){
            Thread.sleep(1000);
            System.out.println(proxy.sayHello("are you ok?"));
        }
    }

}
